package com.czp.infosharingplatformapp;

import com.czp.infosharingplatformapp.config.CorsConfig;
import com.czp.infosharingplatformapp.service.CategoryService;
import com.czp.infosharingplatformapp.service.UserService;

import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.beans.factory.annotation.Autowired;

@SpringBootApplication
public class InfoSharingPlatformAppApplication {

    @Autowired
    private CategoryService categoryService;

    @Autowired
    private UserService userService;

    public static void main(String[] args) {
        SpringApplication.run(InfoSharingPlatformAppApplication.class, args);
    }

    // 添加初始化管理员用户的代码
    @Bean
    public CommandLineRunner initRoles() {
        return args -> {
            userService.initRoles();
        };
    }

    // 当应用启动时，检查并初始化分类
    @Bean
    public CommandLineRunner initializeCategories() {
        return args -> {
            categoryService.initializeCategories(); // 调用分类初始化
        };
    }
}